package com.ccsoft.backuptools;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.util.UrlPathHelper;

@MapperScan(value = "com.ccsoft.backuptools.dao")
@SpringBootApplication
public class BackuptoolsApplication {

    public static void main(String[] args) {
        SpringApplication.run(BackuptoolsApplication.class, args);
    }

    /*解决文件名中含有":\\"等特殊字符时，接口400的问题
     * Tomcat的新版本中增加了一个新特性，就是严格按照 RFC 3986规范进行访问解析，而 RFC 3986规范定义了Url中只允许包含英文字母（a-zA-Z）、数字（0-9）、-_.~4个特殊字符
     * 以及所有保留字符(RFC3986中指定了以下字符为保留字符：! * ’ ( ) ; : @ & = + $ , / ? # [ ])。*/
    @Bean
    public TomcatServletWebServerFactory tomcatServletWebServerFactory (){
        // 修改内置的 tomcat 容器配置
        TomcatServletWebServerFactory tomcatServlet = new TomcatServletWebServerFactory();
        tomcatServlet.addConnectorCustomizers(
                (TomcatConnectorCustomizer) connector -> {
                    connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
                    connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
                }
        );
        System.out.println("重新配置内置 tomcat");
        return tomcatServlet;
    }
}
